package com.hjs.servlet.user;

import com.hjs.bean.UserView;
import com.hjs.mapper.ViewMapper;
import com.hjs.tools.Mapper;
import com.hjs.tools.RequestUtil;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author flamemaster
 * @date 2020/6/17
 * @author violetfreesia
 * @date 2020/6/19 改
 **/
@Slf4j
@WebServlet("/user/search")
public class Search extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) {
        RequestUtil requestUtil = new RequestUtil(request, response);
        Mapper<ViewMapper> viewMapperMapper = new Mapper<>(ViewMapper.class);
        try {
            ViewMapper mapper = viewMapperMapper.getMapper();
            List<UserView> allUserView = mapper.getAllUserView();
            requestUtil.responseWrite(Mapper.toJsonString(allUserView));
        } catch (Exception e) {
            log.error(e.toString());
            requestUtil.responseFail("未知错误");
        } finally {
            viewMapperMapper.closeSession();
        }

    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) {

    }
}
